package com.ourcraft.informationcollectionsystem.controller.province;

import com.alibaba.fastjson.JSONObject;
import com.ourcraft.informationcollectionsystem.entity.Company;
import com.ourcraft.informationcollectionsystem.service.province.filingInfoQuery.FilingInfoQueryService;
import com.ourcraft.informationcollectionsystem.utils.authority.AuthorityCode;
import com.ourcraft.informationcollectionsystem.utils.authority.AuthorityValidator;
import com.ourcraft.informationcollectionsystem.utils.response.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;

@RequestMapping("province/filingInfoQuery/")
@RestController
@CrossOrigin
@AuthorityValidator(code = AuthorityCode.FILLING_INFO_QUERY)
public class FilingInfoQueryController {
    @Autowired
    private FilingInfoQueryService filingInfoQueryService;

    @PostMapping("getRequiredFilingInfoList")
    public Result<List<Company>> getRequiredFormList(@RequestBody JSONObject param, HttpServletRequest request){
        var formQuery = filingInfoQueryService.getRequiredFilingInfoList(param);
        return Result.success(formQuery);
    }

    @GetMapping ("exportCurrentFilingInfoList")
    public ResponseEntity<Resource> exportCurrentFilingInfoList(@RequestParam String params, HttpServletRequest request){
        return filingInfoQueryService.exportCurrentFilingInfoList(
                JSONObject.parseObject(URLDecoder.decode(params, StandardCharsets.UTF_8)));
    }
}
